package com.yocard.yxyd.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.TypedValue;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.webkit.ValueCallback;
import android.widget.ImageView;
import android.widget.TextView;

import com.yocard.yxyd.R;

/**
 * Created on 2019/4/18.
 * 支付对话框
 */
public class PayDialog extends Dialog {

    ImageView ivClose;
    TextView tvPayAmount;
    TextView btnConfirmPay;
    private ValueCallback<String> callback;
    protected String orderId;
    protected String price;

    public PayDialog(@NonNull Context context, ValueCallback<String> callback, String price) {
        super(context, R.style.payDialog);
        this.callback = callback;
        this.price = price;
//        this.callback = callback;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().setGravity(Gravity.BOTTOM);//设置显示在底部
        WindowManager windowManager = getWindow().getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;//设置Dialog的宽度为屏幕宽度
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
//        layoutParams.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 238,getContext().getResources().getDisplayMetrics());
        getWindow().setAttributes(layoutParams);

        setContentView(R.layout.dialog_pay);
        tvPayAmount = findViewById(R.id.tv_pay_amount);
        tvPayAmount.setText(price + getContext().getString(R.string.gold));
        findViewById(R.id.iv_share_bg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.onReceiveValue("");
                dismiss();
            }
        });
        findViewById(R.id.btn_confirm_pay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.onReceiveValue(price);
                dismiss();
            }
        });
    }

//    public void setUpdateListener(ValueCallback<String> callback) {
//        this.callback = callback;
//    }
}
